/**
 * 向后端请求用户的菜单，动态生成路由
 */
import { defaultRoute } from "@/router/defaultRoute";
import {
  generatorDynamicRouter,
} from "@/router/generator-routers";
import { frontendRouter } from "@/router/frontendRouter";

const asyncRouter = {
  state: {
    routers: defaultRoute,
    addRouters: [],
  },
  mutations: {
    SET_ROUTERS: (state, routers) => {
      state.addRouters = routers;
      state.routers = defaultRoute.concat(routers);
    },
  },
  actions: {
    generateRoutes({ commit }, data) {
      return new Promise((resolve) => {
        const { token } = data;
        commit("SET_ROUTERS", frontendRouter);
        resolve();
        // generatorDynamicRouter(token).then((routers) => {
        //   commit("SET_ROUTERS", routers);
        //   resolve();
        // });
      });
    },
  },
};

export default asyncRouter;
